package ua.com.jpy.controllers.admin;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author LSD25
 *
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminLoginController {
	
	private static final Log log = LogFactory.getLog(AdminLoginController.class);
	
//	@RequestMapping(value = { "", "/", "*" }, method = RequestMethod.GET)
//	public String login() {
//		log.info("Redirect to admin/login");
//		return "redirect:/admin/login";
//	}
	
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public ModelAndView loginPage(@RequestParam(value = "loginError", required = false) String loginError) {
		ModelAndView model = new ModelAndView("admin/login");
		if(loginError != null && !loginError.isEmpty()) {
			model.addObject("errorMessage", loginError);
			log.error("Authorization failed!!!");
		}
		log.info("Go to login page.");
		return model;
	}
	
	@RequestMapping(value = { "", "/*", "/home" }, method = RequestMethod.GET)
	public ModelAndView home() {
		ModelAndView model = new ModelAndView("admin/home");
		log.info("Go to home page.");
		return model;
	}

}
